package org.xdq.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xdq.demo.base.PageParam;
import org.xdq.demo.base.Result;
import org.xdq.demo.model.Employee;
import org.xdq.demo.service.TestService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TestController {

    @Autowired
    private TestService testService;

    //public TestController(TestService testService) {
    //    this.testService = testService;
    // }

    @GetMapping("/hello")
    public String sayHello(){
        return "大家好！";
    }

    @GetMapping("/stu")
    public Map<String,Object> stu(){
        Map<String,Object> stu = new HashMap<String,Object>();
        stu.put("stuId","S00001");
        stu.put("stuName","学生1");
        stu.put("stuScore",86);
        return stu;
    }
    @GetMapping("/emp")
    public List<Employee> empList(){

        return testService.getEmpList();

    }

    @DeleteMapping("/emp/{e_id}")
    public Result deleteEmp(@PathVariable String e_id){

        testService.deleteEmp(e_id);
        return Result.success("删除成功！");

    }

    @DeleteMapping("/emp")
    public Result deleteEmp(@RequestBody String[] eids){

        testService.deleteEmp(eids);

        return Result.success("删除成功！");

    }

    @GetMapping("/emp2")
    public Map<String, Object> empList2(PageParam pageParam){

        return testService.getEmpPage(pageParam);

    }


}
